package com.javacoo.xservice.base.support.expression;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import com.javacoo.xkernel.spi.ExtensionLoader;
import com.javacoo.xservice.base.support.expression.config.SpelConfig;

import lombok.extern.slf4j.Slf4j;

/**
 * 表达式解析接口工厂
 * <li></li>
 *
 * @author: duanyong@jccfc.com
 * @since: 2021/3/16 8:56
 */
@Slf4j
@Component
@ConditionalOnBean(SpelConfig.class)
public class ExpressionParserFactory {
    /** 表达式解析配置 */
    @Autowired
    private SpelConfig spelConfig;

    @Bean
    public ExpressionParser createExpressionParser() {
        log.info("初始化表达式解析对象,实现类名称:{}",spelConfig.getImpl());
        ExpressionParserHolder.spelExpressionParser = ExtensionLoader.getExtensionLoader(ExpressionParser.class).getExtension(spelConfig.getImpl());
        log.info("初始化表达式解析对象成功,实现类:{}",ExpressionParserHolder.spelExpressionParser);
        return ExpressionParserHolder.spelExpressionParser ;
    }
}
